import {Button, Dropdown, message} from "antd";
import CustomFileUpload from "@/components/CustomFileUpload";
import {VideoCameraAddOutlined} from "@ant-design/icons";
import {useRef} from "react";
import {MessageType} from "antd/es/message/interface";

const VideoTool = (props: any) => {

  const hideFn = useRef<MessageType>()

  return <Dropdown
    menu={{
      items: [
        {
          key: '1',
          label: <CustomFileUpload
            accept=".mp4"
            onUploadStart={() => {
              hideFn.current = message.loading("上传中...", 0);
            }}
            onUploadSuccess={(res: any) => {
              hideFn.current?.()
              message.success("上传成功")
              console.log(res)
              props?.onUploadSuccess?.(res?.data?.url)
            }}
            onUploadFail={() => {
              console.log('onUploadFail',)
              hideFn.current?.()
            }}
          >上传视频</CustomFileUpload>,
        }
      ]
    }}>
    <Button
      type={'text'}
      icon={<VideoCameraAddOutlined/>}
      onClick={(e) => {
        e.preventDefault()
      }}
    ></Button>
  </Dropdown>
}

export default VideoTool
